/*
 * @Description: 
 * @Author: mmzhang
 * @Date: 2021-12-15 17:16:05
 * @LastEditTime: 2023-01-12 14:30:15
 */
import Opt from '@/components/dt/info/Opt.js'
import subMgr from '@/biz/sales/subOrder.js'
import dateOpt from '@/biz/option/date.js'
import ruleOpt from '@/biz/option/rule.js'
import houseOpt from '@/biz/option/house.js'
import tool from '@/common/tool.js'
import nameOpt from '@/biz/option/name.js'
import caseMgr from '@/biz/crimeSceneList'

let _this = null
class SearchOpt extends Opt {

  constructor(vm) {
    _this = vm
    super()
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }


  createAll() {
    let pushUserList = []

    function getPushName(query) {    
      return caseMgr.getBuildingUserList({ name: query }).then((res) => {
        pushUserList = res || []
        return pushUserList
      })
    }

    let cityAttrSort = []

    this.all = [
      houseOpt.create({
        key: 'buildingId',
        rules:[],
        to: (info) => {
          return {
            buildingId: info.housesId,
            companyId: info.companyId,
            housesName: info.housesName
          }
        }
      }),
      {
        title:'案场主委',
        key: 'chairMan',
        placeholder:'请输入案场主委姓名',
        select: {
          clearable: true,
          filterable: true,
          options: pushUserList.length > 0 ? pushUserList : [],
          remote: (key) => {
            return getPushName(key)
          }
        }
      },
      {
        key: 'cityId',
        title: '所属城市',
        load: (o) => {
          let params = {
            level: 2,
            page: '1',
            parentCode: '',
            rows: '100',
          }
          caseMgr.getAreacodePropertyList(params).then(res => {
            res.list.map((item) => {
              item.value = item.cityCode
              item.label = item.cityName
              item.loading = false
              item.children = []
            })
            o.cascader.options = res.list
            cityAttrSort = res.list
          })
        },
        cascader: {
          options: cityAttrSort,
          loadData(item, callback) {
            item.loading = true;
            let params = {
              level: 3,
              page: '1',
              parentCode: item.value,
              rows: '100',
            };
            caseMgr.getAreacodePropertyList(params).then((res) => {
              res.list.map((itemL) => {
                itemL.value = itemL.cityCode
                itemL.label = itemL.cityName
                item.children.push(itemL)
              })
    
              item.loading = false
              callback()
            })
          }
        }
      },
      {
        title: '案场状态',
        key: 'housesStatus',
        placeholder: '请选择',
        select: {
          key:'buildStatus'
        },
      }
    ]
  }
}

export default SearchOpt